package com.springcloud.alibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.springcloud.alibaba.config.BlockHandler;
import com.springcloud.configclient.commons.entities.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

@RestController
public class SentinelController {
    private AtomicInteger n=new AtomicInteger(1);
    @GetMapping(value = "/get/a")
    public String getA() {
        int k=n.getAndIncrement();
        System.out.println("a"+k);
        return "_________A________"+k;
    }

    @GetMapping(value = "/get/b")
    public String getB() {
        System.out.println("b");
        int n=10/0;
        return "_________B________";
    }

    @GetMapping(value = "/hotkey")
    @SentinelResource(value = "hotkey",blockHandler = "dealHotKey")
    public String hotKey(@RequestParam(value = "p1",required = false) String p1,
                         @RequestParam(value = "p2",required = false) String p2) {
        System.out.println("正常");

        return "--------hotKey---------";
    }
    public String dealHotKey(String p1, String p2,BlockException e) {
        System.out.println("不正常");
        return "---hotkey---"+ p1;
    }

}
